import axios from 'axios'
import { message } from 'antd'
let qs = require('qs')

export default {
    logout() {
        return axios.get('/Users/logout?token=' + sessionStorage.getItem("token"))
            .then(res => {
                return res.data
            }).catch(error => {
                console.log(error)
            })
    },
    axiosPost(url, query) {
        let token = sessionStorage.getItem("token")
        return axios.post(url + '?token=' + token, qs.stringify(query))
            .then(res => {
                if (res.data.error === 99) {
                    message.error('登录超时或者未登录')
                    setTimeout(() => {
                        window.location.href = '/login'
                    }, 500)
                }
                return res.data
            }).catch(error => {
                console.log(error)
            })
    }
}
